package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntTaskStageMapper;
import com.prd.model.EntTaskStage;
import com.prd.model.LoginUser;
import com.prd.service.EntTaskStageService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EntTaskStageServiceImpl extends ServiceImpl<EntTaskStageMapper, EntTaskStage> implements EntTaskStageService {
    @Autowired
    private EntTaskStageMapper entTaskStageMapper;

    @Override
    public int insertInfo(EntTaskStage entTaskStage) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entTaskStage);
        return entTaskStageMapper.insert(entTaskStage);
    }

    @Override
    public int updateInfo(EntTaskStage entTaskStage) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entTaskStage);
        return entTaskStageMapper.updateById(entTaskStage);
    }

    @Override
    public List<EntTaskStage> listInfo(Long taskId) {
        LambdaQueryWrapper<EntTaskStage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EntTaskStage::getTaskId, taskId);
        return entTaskStageMapper.selectList(queryWrapper);
    }
}
